package com.rongc.client.freight.business.mine.view.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Checkable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.rongc.client.freight.R;


/**
 * Created by Bruce on 2017/07/06.
 */
public class CarView extends LinearLayout implements Checkable {
    private TextView mDesc ;
    private ImageView mIv;
    boolean isChecked;

    public CarView(Context context){
        this(context,null);
    }

    public CarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setOrientation(HORIZONTAL);
        setBackgroundResource(R.color.universal_text_white);
        setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.widget_list_car_item, this, true);
        mDesc = (TextView) v.findViewById(R.id.tv_desc);
        mIv = (ImageView)v.findViewById(R.id.iv_check);
    }

    public void setDesc(String desc) {
        mDesc.setText(desc);
    }


    @Override
    public boolean isChecked() {
        return isChecked;
    }

    @Override
    public void setChecked(boolean checked) {
        this.isChecked = checked;
//        refreshDrawableState();
        if(checked){
//            mIv.setImageResource(R.mipmap.fbcy_icon_5);
            mIv.setVisibility(VISIBLE);
        }else{
//            mIv.setImageResource(R.mipmap.fbcy_icon_5);
            mIv.setVisibility(INVISIBLE);
        }
    }

    @Override
    public void toggle() {
        isChecked = !isChecked;
        if(isChecked){
//            mIv.setImageResource(R.mipmap.fbcy_icon_5);
            mIv.setVisibility(VISIBLE);
        }else{
//            mIv.setImageResource(R.mipmap.fbcy_icon_5);
            mIv.setVisibility(INVISIBLE);
        }
    }

}
